package com.huawei.hwphy2d;

import android.annotation.SuppressLint;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.view.ViewGroup;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import o.bqq;

public class HwPhysicalManager implements SensorEventListener {
    static final /* synthetic */ boolean $assertionsDisabled = (!HwPhysicalManager.class.desiredAssertionStatus());
    private static final String TAG = HwPhysicalManager.class.getSimpleName();
    @SuppressLint({"StaticFieldLeak"})
    private HwPhysicalSystem hwPhysicalSystem = null;
    private String mPath;
    private SensorManager sensorManager;

    public HwPhysicalManager(String str) {
        this.mPath = str;
    }

    public void startPhysicalEffect(ViewGroup viewGroup, int i) {
        if (this.hwPhysicalSystem == null) {
            try {
                BufferedReader bufferedReader = new BufferedReader(new FileReader(this.mPath + "particle.json"));
                StringBuilder stringBuilder = new StringBuilder();
                while (true) {
                    String readLine = bufferedReader.readLine();
                    if (readLine == null) {
                        break;
                    }
                    stringBuilder.append(readLine);
                }
                this.hwPhysicalSystem = new HwPhysicalSystem(viewGroup, 2, stringBuilder.toString(), this.mPath);
            } catch (IOException e) {
                bqq.ॱ.ˊ(TAG, e.toString());
            }
            this.sensorManager = (SensorManager) viewGroup.getContext().getSystemService("sensor");
            if ($assertionsDisabled || this.sensorManager != null) {
                this.sensorManager.registerListener(this, this.sensorManager.getDefaultSensor(1), 2);
                this.hwPhysicalSystem.initPhysicalSystem();
                this.hwPhysicalSystem.play();
                if (i > 3) {
                    this.hwPhysicalSystem.getHwPhysicalView().setRotation(180.0f);
                    return;
                }
                return;
            }
            throw new AssertionError();
        }
    }

    public void stopPhysicalEffect() {
        if (this.hwPhysicalSystem != null) {
            this.sensorManager.unregisterListener(this);
            this.hwPhysicalSystem.stop();
            this.hwPhysicalSystem.destroy();
            this.hwPhysicalSystem = null;
        }
    }

    public void onSensorChanged(SensorEvent sensorEvent) {
    }

    public void onAccuracyChanged(Sensor sensor, int i) {
    }
}
